#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.63])
AC_INIT(gvirtus-cudnn, 01-beta2, http://osl.uniparthenope.it/mailman/listinfo/gvirtus-devel)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([frontend/Cudnn.cpp])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_LIBTOOL

AC_ARG_WITH([cudnn-include], [AC_HELP_STRING([--with-cudnn-include=PATH],
    [set PATH to the CUDNN include directory])], [
    CUDNN_INCLUDE="$withval"
    CUDNN_FLAGS="-isystem $CUDNN_INCLUDE"
], [
    CUDNN_FLAGS="$CUDNN_FLAGS -isystem /usr/local/cuda/include/"
    CUDNN_FLAGS="$CUDNN_FLAGS -isystem /opt/cuda/include"
])
CPPFLAGS="$CPPFLAGS $CUDNN_FLAGS"

AC_ARG_WITH([cudnn-lib], [AC_HELP_STRING([--with-cudnn-lib=PATH],
    [set PATH to the CUDNN library directory])],
    [
    CUDNN_LIB_DIR="$withval"
    CUDNN_LIB_FLAGS="-L$withval"
], [
    CUDNN_LIB_FLAGS="$CUDNN_LIB_FLAGS -L/usr/local/cuda/lib64"
    CUDNN_LIB_FLAGS="$CUDNN_LIB_FLAGS -L/usr/local/cuda/lib"
    CUDNN_LIB_FLAGS="$CUDNN_LIB_FLAGS -L/opt/cuda/lib"
    CUDNN_LIB_FLAGS="$CUDNN_LIB_FLAGS -L/opt/cuda/lib64"
])
LDFLAGS="$LDFLAGS $CUDNN_LIB_FLAGS"
AC_SUBST(CUDNN_LIB_FLAGS)

AC_ARG_WITH([gvirtus-include], [AC_HELP_STRING([--with-gvirtus-include=PATH],
    [set PATH to the GVirtuS include directory])], [
    GVIRTUS_INCLUDE="$withval"
    GVIRTUS_FLAGS="-I$GVIRTUS_INCLUDE"
], [
    GVIRTUS_FLAGS="$GVIRTUS_FLAGS -I${prefix}/include/gvirtus"
    GVIRTUS_FLAGS="$GVIRTUS_FLAGS -I/usr/local/gvirtus/include/gvirtus"
    GVIRTUS_FLAGS="$GVIRTUS_FLAGS -I/opt/gvirtus/include/gvirtus"
#    GVIRTUS_FLAGS="$GVIRTUS_FLAGS -I/home/rapid/opt/include/gvirtus"
#    GVIRTUS_FLAGS="$GVIRTUS_FLAGS -I${prefix}/include/gvirtus"
])
CPPFLAGS="$CPPFLAGS $GVIRTUS_FLAGS"

AC_ARG_WITH([gvirtus-lib], [AC_HELP_STRING([--with-gvirtus-lib=PATH],
    [set PATH to the GVirtuS library directory])],
    [
    GVIRTUS_LIB_DIR=$withval
    GVIRTUS_LIB_FLAGS="-L$withval"
], [
    GVIRTUS_LIB_FLAGS="-L${prefix}/lib"
    GVIRTUS_LIB_FLAGS="$GVIRTUS_LIB_FLAGS -L/usr/local/gvirtus/lib"
    GVIRTUS_LIB_FLAGS="$GVIRTUS_LIB_FLAGS -L/opt/gvirtus/lib"
   # GVIRTUS_LIB_FLAGS="$GVIRTUS_LIB_FLAGS -L/home/rapid/opt/lib"
   # GVIRTUS_LIB_FLAGS="-L${prefix}/lib"
])
LDFLAGS="$LDFLAGS $GVIRTUS_LIB_FLAGS"
AC_SUBST(GVIRTUS_LIB_FLAGS)


# Checks for libraries.
#AC_CHECK_LIB([cudart], [__cudaRegisterFatBinary], , AC_MSG_ERROR([Could not find the cuda library.]))
#LIBS=""

# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h sys/socket.h unistd.h vmci/vmci_sockets.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UINT32_T

# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([gethostbyname memmove memset socket strcasecmp strdup strtoul])

AC_CHECK_HEADER([cudnn.h], [], [
    AC_CHECK_HEADER([cudnn.h], ,
        [
            AC_MSG_ERROR([Could not find the cudnn header.])
        ])])

CPPFLAGS="-I`pwd`/util $CPPFLAGS"
CXXFLAGS="$CXXFLAGS -Wall -pedantic -llog4cplus"
#AC_CONFIG_FILES([Makefile 
#                 util/Makefile
#                 backend/Makefile
#                 frontend/Makefile
#                 test/Makefile
#       ])


AC_CONFIG_FILES([Makefile
                 frontend/Makefile
                 backend/Makefile
        ])
AC_OUTPUT
